package com.jiaai.web.gift;

import com.alibaba.dubbo.config.annotation.Reference;
import com.jiaai.auth.model.AccessUser;
import com.jiaai.exception.ServerException;
import com.jiaai.filter.aop.TokenIntercept;
import com.jiaai.gift.api.IGiftHisApi;
import com.jiaai.util.RequestUtils;
import com.jiaai.util.RestResultGenerator;
import org.springframework.web.bind.annotation.*;

/**
 * class_name:ZGiftHisController
 * describe:TODO
 * create_user:张昉平
 * create_date:2018/1/9
 * create_date:12:21
 */
@RestController
@RequestMapping("/api/v1/app/")
public class ZGiftHisController {

    @Reference
    private IGiftHisApi iGiftHisApi;

    /**
     * 查询礼物历史记录, 我赠送的, 我收到的
     * @param yearMonth
     * @param type get:收到的 send:赠送的
     * @return
     * @throws ServerException
     */
    @GetMapping("giftHis/his/{yearMonth}")
    @TokenIntercept(checkVisitor = true)
    public Object get(@PathVariable String yearMonth, @RequestParam String type)throws ServerException {
        AccessUser user = RequestUtils.getUser();
        try {
            return  RestResultGenerator.genSuccessResult(iGiftHisApi.getAppHis(user.getUserId(), yearMonth, type));
        }catch (Exception e){
            e.printStackTrace();
            return RestResultGenerator.genErrorResult("服务器异常");
        }
    }

    /**
     * vip, 守护, 充值, 座驾, 靓号, 提现 记录
     * @param yearMonth
     * @param type vip:vip, guard:守护 , pay:充值 , tx:提现, car:座驾, gn:靓号
     * @return
     */
    @GetMapping("/propHis")
    @TokenIntercept(checkVisitor = true)
    public Object propHis(@RequestParam String yearMonth, @RequestParam String type){
        AccessUser user = RequestUtils.getUser();
        return RestResultGenerator.genSuccessResult(iGiftHisApi.getPropHis(yearMonth, type, user.getUserId()));
    }
}
